<template>
	<view class="page">
		<q-navbar title="我的" :isBack="false" />
		<view class="info">
			<q-image :src="userInfo.avatarImg" :width="150" :height="150" radius="50%" />
			<view class="userName">
				{{userInfo.userName}}
				{{userInfo.phonenumber}}
			</view>
		</view>
		<view class="menulist-box" v-for="(item ,index) in menusList" :key="index" @click="checkMenu(item,index)">
			<view class="name-box">
				<img :src="item.icon" alt="">
				<view class="title-box">
					{{item.name}}
				</view>
			</view>
			<view class="total-box">
				<u-icon name="arrow-right" color="#999999"></u-icon>
			</view>
		</view>
		<q-tabbar :current='2' />
	</view>
</template>

<script>
	export default {
		components: {},
		props: {},
		data() {
			return {
				userInfo: {},
				menusList: [{
					name: '个人信息',
					icon: require('@/static/images/wode-xz@2x.png'),
					path: '/pages/my/detail/detail'
				}, {
					name: '我的预约',
					icon: require('@/static/images/cg_.png'),
					path: '/pages/reservation/reservation'
				}, {
					name: '消息列表',
					icon: require('@/static/images/yijianjianyi@2x.png'),
					path: '/pages/message/index'
				}, {
					name: '评价列表',
					icon: require('@/static/images/qiye-icon@2x.png'),
					path: '/pages/evaluate/evaluate'
				}]
			}
		},
		watch: {},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {},
		onLoad(options) {},
		onShow() {
			this.findUser()
		},
		methods: {
			// 查用户头像
			async findUser() {
				let res = await this.$api.getInfo(this.$s.get('userId'))
				this.userInfo = res.data
				this.$s.set('userInfo', res.data)
				if (!!res.data.avatar || res.data.avatar !== '') {
					this.userInfo.avatarImg = this.$img + res.data.avatar
				}
			},
			checkMenu(item, index) {
				if (item.path === '') {
					this.$msg.default('正在开发中...')
				} else {
					this.router.push({
						path: item.path,
						time: 0
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;
		display: flex;
		flex-direction: column;

		.info {
			display: flex;
			align-items: center;
			padding: 20rpx 40rpx;

			.userName {
				margin-left: 40rpx;
				font-weight: 700;
				font-size: 32rpx
			}
		}

		.menulist-box {
			margin: 40rpx 30rpx;
			padding: 30rpx 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1px solid #e8e8e8;

			.name-box {
				display: flex;
				align-items: flex-start;

				img {
					width: 48rpx;
					height: 48rpx;
					border-radius: 50%;
					margin-right: 10rpx;
				}
			}
		}
	}
</style>